<?php

use Biz\service\springHomeDecActivity\Util;
use Doraemon\model\ForbiddenWord\ForbiddenSceneWord as mForbiddenSceneWordModel;
use Doraemon\service\ForbiddenWord\ForbiddenSceneWord as sForbiddenSceneWord;

class ForbiddenSceneWordAction extends ActionPlugin
{

    const USER_LEVEL = self::LEVEL_REGISTER;

    const VALIDATOR_TOAST_DEBUG = true;

    //参数校验-规则
    public const VALIDATOR_RULES = [
        'idea' => 'require',
    ];

    //参数校验-自定义消息
    public const VALIDATOR_MSG = [
        'idea.require' => '住家理念、感悟未填写',
    ];

    public function main()
    {
        $lockKey = 'spring_home_dec_act:forbidden_scene_word:' . $this->uid;
        Util::lockSubmit($lockKey);

        $idea = $this->params['idea'];
        if (empty($idea)) {
            throw new \Exception("检测内容不能为空", self::CODE_ERROR_VIEW_TOSTA);
        }
        //敏感词检测
        $ideaForbidden = new sForbiddenSceneWord(mForbiddenSceneWordModel::CONTENT, $idea, sForbiddenSceneWord::IDEA);
        if ($ideaForbidden->getHit() && !$ideaForbidden->getPublish()) {
            throw new \Exception("error:forbidden", self::CODE_ERROR_VIEW_TOSTA);
        }
        $this->setSuccess('success');
    }
}